package com.shigen.demo.atguigu;

import java.util.HashMap;
import java.util.WeakHashMap;

/**
 * @author shigenfu
 * @date 2022/5/26 1:04 下午
 */
public class WeakHashMapDemo {

  public static void main(String[] args) {
    HashMap<Integer, String> map = new HashMap<>();
    Integer key = 1;
    String value = "hashMap";

    map.put(key, value);
    System.out.println(map);
    key = null;
    System.out.println(map);
    System.gc();
    System.out.println(map);

    System.out.println("===========");


    WeakHashMap<Integer, String> weakHashMap = new WeakHashMap<>();
    Integer key1 = new Integer(2);
    String value1= "hashMap2";

    weakHashMap.put(key1, value1);
    System.out.println(weakHashMap);
    key1 = null;
    System.out.println(weakHashMap);
    System.gc();
    System.out.println(weakHashMap);

  }




}
